问题描述
|
我从网站上获得了单击元素的ID,并且我需要检查ID是否包含特定单词。 (所有ID均以相同的单词开头,但也有一个所有人都传出的数字)。
我该如何使用jQuery?
解决方法
用
search()
$(\".foo\").click(function(){
if(this.id.search(\"certainword\")>=0)
{
alert(\"found you!\");
}
});
, 这应该做到这一点:
ID包含\“ Box1 \”并且为Class1
$(function() {
$(\"div[id*=\'Box1\'] + .Class1\").html(\"Test\");
})
例:
http://jsfiddle.net/fP5YB/1/
, 我会使用indexOf:
var matchString = \"foo\";
if (matchString.indexOf(yourID) >= 0) {
// string was found
}
, 尝试以下方法;
<script>
$(function(){
$.each($(\"input[id^=\'poo\']\"),function () {
var _in = $(this);
var _inputid = _in.attr(\'id\');
var _isInputChecked = _in.is(\':checked\');
var _rowIndex = _inputid.substring(_inputid.length,_inputid.length - 1);
alert(_rowIndex);
});
});
</script>
<input type=\"radio\" name=\"sex\" value=\"male\" checked=\"checked\" id=\"poo1\" /> Male<br />
<input type=\"radio\" name=\"sex\" value=\"female\" id=\"poo2\" /> Female <br />
<input type=\"radio\" name=\"sex\" value=\"female\" checked=\"checked\" id=\"poo3\" /> Unknown