Can I pass the button ID dynamically?
$('#Button1').focus(function () {
if (document.getElementById('HiddenVal').value != null && document.getElementById('HiddenVal').value != '') {
$('#txtbox1').val(document.getElementById('HiddenVal').value);
$('#Button1', window.parent.document).css("background-color", "#fcc63b");
document.getElementById('HiddenVal').value = '';
}
开发者_开发问答 });
Here I want to pass the button ID dynamically instead of using $('#Button1')
.
Can I use that?
yes you can- place your code inside a function...and pass id as a parameter to that function - like this..
function dynamicId(id){
newId = '#'+id
$(newId ).focus(function () {
...
...
});
}
Seems like your code could be written as :
$('#Button1').focus(function () {
var hiddenValue = $('#HiddenVal').val();
if (hiddenValue != null && hiddenValue != '') {
$('#txtbox1').val($(hiddenValue );
$(this).css("background-color", "#fcc63b");
$('#HiddenVal').val('');
}
});
Regards,
Max
精彩评论