开发者

find out if a certain id itself has certain text part of it

I got the id of a clicked element from the site, and i need to check if the id has a certain word. (all the id start with same word but have also a number which is efferent for all).

How can i d开发者_JAVA技巧o that with jquery?


This should do it :

ID Contains "Box1" and is Class1

$(function() {
   $("div[id*='Box1'] + .Class1").html("Test");
})

Example:

http://jsfiddle.net/fP5YB/1/


Use search()

$(".foo").click(function(){

    if(this.id.search("certainword")>=0)
    {
    alert("found you!");
    }

});


I'd use indexOf:

var matchString = "foo";
if (matchString.indexOf(yourID) >= 0) {
  // string was found
}


Try the following;

<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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜