在我的应用程序有一个标记像这些简单和干净的方式来替代在JQuery的ID选择变量值
<div id="divLeft" style = " width: 300px; border: 1px solid red; float: left" onclick="DoThis('textId')">
<input type="text" id="textId" />
</div>
<div id="divRight" style = " width: 600px; border: 1px solid red; float: right" onclcick="DoThat()">
</div>
,并在Java脚本事件处理程序的代码,我检索我使用文本ID元素id选择器为
function DoThis(id){
//some code goes here
$("#"+id).show();
//some code goes here
}
并且有数百个地方正在进行字符串连接,如“#”+ somID,这对我来说看起来很糟糕。我想知道是否有某种方式或jQuery的选择器API,如$.id(someID)
或什么会避免这种字符串连接?
问候, 哎呀
为什么你不想执行字符串连接? “这对我来说很不好。”为什么? –
真正的问题是你为什么要使用内联处理程序。 Unobtrusive JS是你的朋友。 – prodigitalson
@Boopathi,即使我不喜欢字符串连接..你有什么建议? – JeeZ