开发者

how to read character behind some text

开发者 https://www.devze.com 2023-01-02 10:50 出处:网络
this one a code for read two character behind text \"KD-R411ED\" var code = data[0].substr(data[0].length - 2);

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

精彩评论

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