如何在 jquery 选择器中将字符串与 javascript 变量连接起来? 如果我执行下面的代码。所有其他表单元素都被隐藏。
var inputatr = $('input[type=text]').attr(); //button
$('input[value=string ' + inputatr +']').hide(); //textbox
更新
<?php for($x=0; $x<4; $x++){ ?>
<input type="text" id="<?php echo $x; ?>" name="<?php echo $x; ?>" value="text<?php echo $x; ?>"/>
<input type="button" name="show<?php echo $x; ?>" value="string<?php echo $x; ?>"/></li>
<?php } ?>
最佳答案
$('input[value="string' + inputatr +'"]').hide();
这会隐藏值等于inputatr
的输入
关于javascript - 如何在jquery选择器中连接字符串和javascript变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5911815/