开发者

how to read character behind some text

this one a code for read two character behind text "KD-R411ED"

var code = data[0].substr(data[0].length - 2);

how to read ED character if text like KD-R411H2EDT? i want a new code can combine with code above..please help!!

look this:

    <script type="text/javascript">
$("#tags1").change(function() {
                                                    var barcode;
                                                    barCode=$("#tags1").val();
                                                       var data=barCode.split(" ");
                                                       $("#tags1").val(data[0]);
                                                       $("#tags2").val(data[1]);

                                                    var code = data[0].substr(data[0].length - 2); // suggested by Jan Willem B

                                                      if (code == 'UD') {
                                                                            $('#check1').attr('checked','checked');
                                                    } else {
                                                            if (code == 'ED') {
                                                                            $('#check2').attr('checked','checked');
             开发者_如何学C                                       }
                                                     }
</script>

and this one

<input id="check1" type="radio" class="check" name="check" onclick="addtext()" value="U" />U

<input id="check2" type="radio" class="check" name="check" onclick="addtext_1()" value="E" />E


I seems like you are trying to determine if the characters 'ED' or 'UD' are present in a string. If this is the case, you want to use regular expressions.

Try here: http://www.w3schools.com/jsref/jsref_obj_regexp.asp

or here: http://www.javascriptkit.com/javatutors/re.shtml


you can control from string like that

if (data[0].indexof('UD') > -1)
{
...
}else{

if(data[0].indexof('ED') > -1)
   {

   }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜