如何使用Java脚本/jQuery将字符串附加到运行时间HTML属性值



html代码

a) <input type="text" id="1" name="Q-1>1>1=1" value="SELECT" style="width: 60px; height: 25px; text-align: center; cursor: pointer; border: 2px solid black;" onfocus="this.blur()" onclick="getTriStateMarks(this)" ;="">

b)<input type="text" id="1O" name="Q-1>1>1=1" value="SELECT" style="width: 60px; height: 25px; text-align: center; cursor: pointer; border: 2px solid black; display:none" onfocus="this.blur()" onclick="getTriStateMarks(this)" ;="">

我需要将 b 的显示属性更改为 'block'

解决方法:

var strNotApplicableControlName = $(htmControl).attr('id'); //return value is 1 (id of A)
strNotApplicableControlName = strNotApplicableControlName.concat("O");
//strNotApplicableControlName = strNotApplicableControlName + "O"; //Not working
//using js
document.getElementById(strNotApplicableControlName).style.display = 'block';
//using jQuery
$(strNotApplicableControlName).css('display','block');
$("'" + strNotApplicableControlName + "'").css('display','block');

限制的输出:

"1"O

我毫无疑问地确定这个问题。感谢您的帮助。

使用$('[id=1O]')选择元素,请查看下面的摘要以查看其工作原理

var dynamicid = 1;
$('[id='+dynamicid+'O]').css("display","block");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="1" name="Q-1>1>1=1" value="SELECT" style="width: 60px; height: 25px; text-align: center; cursor: pointer; border: 2px solid black;" onfocus="this.blur()" onclick="getTriStateMarks(this)" ;="">
<input type="text" id="1O" name="Q-1>1>1=1" value="SELECT" style="width: 60px; height: 25px; text-align: center; cursor: pointer; border: 2px solid black; display:none" onfocus="this.blur()" onclick="getTriStateMarks(this)" ;="">

尝试这个 -

$('#10')。css('display','block');

您可以使用JavaScript:

document.getElementById('1O').style.display = 'block';
<input type="text" id="1" name="Q-1>1>1=1" value="SELECT" style="width: 60px; height: 25px; text-align: center; cursor: pointer; border: 2px solid black;" onfocus="this.blur()" onclick="getTriStateMarks(this)" ;="">
<input type="text" id="1O" name="Q-1>1>1=1" value="SELECT" style="width: 60px; height: 25px; text-align: center; cursor: pointer; border: 2px solid black; display:none" onfocus="this.blur()" onclick="getTriStateMarks(this)" ;="">

或jQuery:

$('#1O').css('display', 'Block');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="1" name="Q-1>1>1=1" value="SELECT" style="width: 60px; height: 25px; text-align: center; cursor: pointer; border: 2px solid black;" onfocus="this.blur()" onclick="getTriStateMarks(this)" ;="">
<input type="text" id="1O" name="Q-1>1>1=1" value="SELECT" style="width: 60px; height: 25px; text-align: center; cursor: pointer; border: 2px solid black; display:none" onfocus="this.blur()" onclick="getTriStateMarks(this)" ;="">

相关内容

  • 没有找到相关文章

最新更新