简体   繁体   中英

How to check if a string contains a given string using jQuery

I Use this Code to check a char is contain in string if true checked checkbox but it always return true.why??

//it is mvc project and after execution it become like this:if ($("123:contains(1)"))
if ($("@Model.VillageAR.IncomeLocation.ToString():contains(1)")) 
{
    $('#IncomeLocation1').attr('checked', true);
}

I'm guessing you're really just looking for indexOf

if ( "@Model.VillageAR.IncomeLocation.ToString()".indexOf('1') != -1 ) {
    $('#IncomeLocation1').prop('checked', true);
}

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