Php Jquery没有关注正确的字段
在jquery中运行计算后,我试图将焦点放在我的isbn文本框或edition文本框中,但它将转到页面上的第一个按钮或sales rank字段 我的html是:Php Jquery没有关注正确的字段,php,jquery,Php,Jquery,在jquery中运行计算后,我试图将焦点放在我的isbn文本框或edition文本框中,但它将转到页面上的第一个按钮或sales rank字段 我的html是: <td><label>ISBN</label></td> <td><input type="text" id="isbn" name="isbn" /></td> <td>
<td><label>ISBN</label></td>
<td><input type="text" id="isbn" name="isbn" /></td>
<td></td>
<td rowspan=7><a id="detailURL" href="#" target="_blank"><img id="bookCover" src="../images/imgNotFound.gif" height="200px" /></a></td>
<td rowspan=7><input type="button" id="isIE" name="isIE" value="IE Price Reduction" />
<br/><br/><input type="button" id="isAIE" name="isAIE" value="AIE Price Reduction" />
<br/><br/><input type="button" id="isModHighlight" name="isModHighlight" value="Moderate Highlighting" />
<br/><br/><input type="button" id="isHeavHighlight" name="isHeavHighlight" value="Heavy Highlighting" />
<br/><br/><input type="button" id="isMissingSupply" name="isMissingSupply" value="Missing Supply" />
<br /><br/><input type="button" id="waterDamage" name="waterDamage" value="Water Damage / Poor Cond." />
</td>
<td rowspan=7>
<!-- SUPPLY CHECK TABLE -->
<table id="supply" summary="Check Supply" width="10%" border="1" align="right">
<caption><h3>Check Supply!</h3></caption>
<thead>
<tr>
<th scope="col" class="rounded-isbn">Supply:</th>
<!--<th scope="col" class="rounded-isbn">Who Requires:</th>-->
</tr>
</thead>
<tbody>
</tbody>
</table>
</td>
</tr>
<tr>
<td><label for="quantity" class="label">Quantity</label></td>
<td><input type="text" id="quantity" name="quantity" /></td>
<td></td>
</tr>
<tr>
<td><label for="payPrice" class="label">Price to Pay</label></td>
<td><input type="text" id="payPrice" name="payPrice"/></td>
<td></td>
</tr>
<tr>
<td><label>Edition</label></td>
<td><input type="text" id="edition" name="edition" readonly="readonly"/></td>
<td></td>
</tr>
<tr>
<td><label>Title</label></td>
<td><input type="text" id="title" name="title" /></td>
<td></td>
</tr>
<tr>
<td><label>Sales Rank</label></td>
<td><input type="text" id="salesRank" name="salesRank" readonly="readonly" /></td>
<td></td>
</tr>
<tr>
<td></td><td><input type="button" id="buy" value="Buy" /></td><td></td>
</table>
</form>
ISBN
检查供应!
供应:
量
付出的代价
版本
标题
销售排名
所讨论的jquery是:
if($('#payPrice').val() <= 0 ) {
$(':text')[0].focus();
} else {
$("#edition").focus();
}
if($('#payPrice').val()你试过了吗
if(parseFloat($('#payPrice').val()) <= 0 ) {
...
}
阅读我建议使用更好的选择器:
例如$('[type=text]')
或$('input:text')
请参阅:这是最终结果,感谢杰克特基为我指明了正确的方向
//focus on either isbn or edition
setTimeout(function() {
if($('#payPrice').val() <= 0 ) {
$("#isbn").focus();
} else {
$("#edition").focus();
}
}, 10);
//关注isbn或版本
setTimeout(函数(){
如果在parseFloat中添加($('#payPrice').val()没有起到作用,那么它仍然关注错误的项目。不过,感谢您的思考。
function sampledFunction()
{
window.setTimeout(function ()
{
$('#mobileno').focus();
}, 0);
return false;
}
//focus on either isbn or edition
setTimeout(function() {
if($('#payPrice').val() <= 0 ) {
$("#isbn").focus();
} else {
$("#edition").focus();
}
}, 10);