开发者

Need help with jQuery Selector

This should be simple but is boggling me for some reason. I'm sure it's syntax thing I'm messing up.

I have a bunch of Submit buttons on a page. (It is a Survey website). Each submit button goes with a specific part of the form, so the button is disabled until until the required elements are filled out. In order to help me tie the correct submit button to the correct elements, I have the ID and NAME set to include the word "submit" plus the GUID of the question in the database. (This is an ASP.NET website). So for example, when ASP.NET renders the page, it creates this:

<input type="submit" id="MainContent_ctl00_submitc03d5172-f7fa-4e9c-a762-3261461befbd" value="Submit Response" name="ctl00$MainContent$ctl00$submitc03d5172-f7fa-4e9c-a762-3261461befbd">

I r开发者_开发问答eally just want to grab anything that has an ID (or a name) that ends with "submitc03d5172-f7fa-4e9c-a762-3261461befbd".

Bear in mind that each GUID of each button is different, so I pass the GUID to the function.

My javascript function looks like this:

function enableSubmit(id) {
    $('input[id$="submit" + id]').button('enable'); 
}

But that is not working, and I don't know why. Please help...


Try this

function enableSubmit(id) {
    $('input[id$="submit' + id + '"]').attr('disabled', false); 
}


The correct geeneration of selector string would be

$('input[id$="submit' + id + '"]')

Also, from documentation, to enable jquery button after initialization (not when first creating)

Get or set the disabled option, after init.
//getter
var disabled = $( ".selector" ).button( "option", "disabled" );
//setter
$( ".selector" ).button( "option", "disabled", true );

See this jsfiddle for complete example


Try the contains selector

function enableSubmit(id) {
    $('input[id*="submit' + id + '"]').attr('disabled', false); 
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜