有没有办法将连接的JavaScript字符串传递给JQuery变量?
示例:
HTML:
<input id="Faculty1input" style="width:100%" />
<input id="Faculty2input" style="width:100%" />
<input id="Faculty3input" style="width:100%" />
<input id="Faculty4input" style="width:100%" />
<input id="Faculty5input" style="width:100%" />
<input id="Faculty6input" style="width:100%" />
<input id="Faculty7input" style="width:100%" />
<input id="Faculty8input" style="width:100%" />
<input id="Faculty9input" style="width:100%" />
<input id="Faculty10input" style="width:100%" />
JS:
for(x=1;x<=10;x++){
var str2 = 'Faculty';
var str3 = x;
var str4 = 'input';
var input = str2.concat(str3,str4);
if( $.trim( $("#" + input).val() ) == ''){
...
}
}
答案 0 :(得分:0)
很抱歉没有根据标题明确回答您的问题,但是为此更容易/更好地使用类,或者,如果您对页面上的所有输入执行此操作,只需使用$(".thumb").mouseenter(function() {
var id = this.id.slice(this.id.length - 1, this.id.length);
id = "#info" + id;
$(".info").each(function() {
$(this).hide();
});
$(id).show();
});
:
$('input').each()
&#13;
$('input').each(function() {
if ($.trim($(this).val()) == '') {
document.write('foo<br>')
}
})
&#13;
或者上课:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="Faculty1input" style="width:100%" />
<input id="Faculty2input" style="width:100%" />
<input id="Faculty3input" style="width:100%" />
<input id="Faculty4input" style="width:100%" />
<input id="Faculty5input" style="width:100%" />
<input id="Faculty6input" style="width:100%" />
<input id="Faculty7input" style="width:100%" />
<input id="Faculty8input" style="width:100%" />
<input id="Faculty9input" style="width:100%" />
<input id="Faculty10input" style="width:100%" />
&#13;
$('.faculty').each(function() {
if ($.trim($(this).val()) == '') {
document.write('foo<br>')
}
})
&#13;