javascript 验证 - 仍检测到 rbColorId 对象
function submitcheck()
{
var f = document.form1;
if (f.rbTemplate!= null)
{
...
alert('Please choose template');
return false;
...
}
if (f.rbColorId!= null)
{
...
alert('Please choose template color');
return false;
...
}
}
function ShowColor()
{
var f= document.form1;
iTemplate= getSelectedRadioValue(f.rbTemplate);
var params= "iTemplate="+iTemplate;
var url= "ajaxColor.php";
doShowOutput(params, url, retrieveColorsAvailableForThisTemplate);
}
function retrieveColorsAvailableForThisTemplate()
{
if(httpObject.readyState == 4)
{
document.getElementById('showtime').style.display="";
document.getElementById('showtime').innerHTML= httpObject.responseText;
}
}
<input type='radio' name='rbTemplate' id=1 value=1 onclick='ShowColor();'>
<img src="template1.jpg" />
<br />
<input type='radio' name='rbTemplate' id=2 value=2 onclick='ShowColor();'>
<img src="template2.jpg" />
<div id=showtime></div>
当单击 rbTemplate id=1 时,ajax 查询将将此模板的可用颜色返回到 id=showtime
例如:
<table>
<tr>
<td bgColor="#FF0000"><input type=radio name=rbColorId id=1 value=1></td>
<td bgColor="#FF0007"><input type=radio name=rbColorId id=2 value=2></td>
<td bgColor="#FF0003"><input type=radio name=rbColorId id=3 value=3></td>
</tr>
</table>
当单击 rbTemplate id=2 时,ajax 将输出作为简单消息返回到 id=showtime 中,因为该模板实际上不'没有任何颜色选择)
例如: 此模板没有任何颜色“
现在的问题是:
第 1 步:在我单击 rbTemplate id=1 后且没有选择颜色,然后点击提交(javascript会提示我选择颜色),
步骤2:然后我再次重复点击rbTemplate id=2,再次点击提交,此时,它不应该提示选择颜色,因为这个第二个模板没有颜色。但 javascript 提示仍然出现。 JS 验证仍然能够检测到 f.rbColorId (可能来自缓存或...)...帮助...
帮助
function submitcheck()
{
var f = document.form1;
if (f.rbTemplate!= null)
{
...
alert('Please choose template');
return false;
...
}
if (f.rbColorId!= null)
{
...
alert('Please choose template color');
return false;
...
}
}
function ShowColor()
{
var f= document.form1;
iTemplate= getSelectedRadioValue(f.rbTemplate);
var params= "iTemplate="+iTemplate;
var url= "ajaxColor.php";
doShowOutput(params, url, retrieveColorsAvailableForThisTemplate);
}
function retrieveColorsAvailableForThisTemplate()
{
if(httpObject.readyState == 4)
{
document.getElementById('showtime').style.display="";
document.getElementById('showtime').innerHTML= httpObject.responseText;
}
}
<input type='radio' name='rbTemplate' id=1 value=1 onclick='ShowColor();'>
<img src="template1.jpg" />
<br />
<input type='radio' name='rbTemplate' id=2 value=2 onclick='ShowColor();'>
<img src="template2.jpg" />
<div id=showtime></div>
when click on rbTemplate id=1, ajax query will return the available colors for this template into id=showtime
eg:
<table>
<tr>
<td bgColor="#FF0000"><input type=radio name=rbColorId id=1 value=1></td>
<td bgColor="#FF0007"><input type=radio name=rbColorId id=2 value=2></td>
<td bgColor="#FF0003"><input type=radio name=rbColorId id=3 value=3></td>
</tr>
</table>
when click on rbTemplate id=2, ajax return the output as simple message into id=showtime, because this template actually don't have any color selection)
eg: "<p>this template don't have any color</p>"
Problem now is :
Step 1: after I click on rbTemplate id=1 and without select color, then click submit (javascript will prompt me to select color),
Step 2: then I repeat again by clicking on rbTemplate id=2, click submit again, at this time, it shouldn't prompt for color selection, because this second template don't have color. BUT javascript prompt still appear. JS validation still able to detect f.rbColorId (maybe from cache or...)... Help...
Help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您只是输出 Ajax 调用的结果,我想说您需要更改 ajaxColor.php 中的逻辑,
但是如果您确实不需要颜色,为什么不完全删除该事件呢?
As you are just outputting the result from the Ajax call, I'd say you need to change your logic in ajaxColor.php
But if you don't really need the color thing, why not remove the event completely?