简体   繁体   中英

looking for method to check string that contains some word

i am doing dynamic tooltip, basically what i am trying to achieve is to detect multiline tooltips, if my data inside contains \\r, then i will perform some action, the code below is a sample that i am trying to check my description, but i failed.

Note: My main object is to check the contains of my description

<script type="text/javascript">
// description
var data = {
    name: "enter your name",
    family: "enter your \r family",
    uc2_txtname: "enter your name for Control 2 (User Control2)",


}
function Show(){
var text = '';
// failed to check my above data , the data.contains('\r') is not working
        if (data.contains('\r')) {
            text = 'good';
        } else {
            text = 'bad';
        }
}

</script>

You should use indexOf instead of contains (javascript has no support for that function).

function Show(){
    var text = '';
    for(var d in data){
        var val = data[d];
        if (val.indexOf('\r') != -1) { 
            text = 'good';
        } else {
            text = 'bad';
        }
    }
}        

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM