开发者

Using jquery .attr - change src of iframe to be "script.php?=" + (#url).text

I have a simple text box and button.

When clicked the button should 开发者_StackOverflow社区change the src attribute of an iframe as follows:

src="**script.php?=**(value of text box)

I have managed to get the iframe to work when simply changing the src to be only the contents of the text box using this code:

$(document).ready(function() {

// Change iFrame on a Button Click Event
    $("#myButton").click(function(event){
        $("#myIFrame").attr('src', $('#url').val());
    });
});

How can i add the "script.php?=" before the $('#url').val()

Thanks!!!!


$(document).ready(function() {

// Change iFrame on a Button Click Event
    $("#myButton").click(function(event){
        $("#myIFrame").attr('src', 'script.php?=' + $('#url').val());
    });
});


Just concatenate it:

$(document).ready(function() {
    var prefix = 'script.php?=';
    // Change iFrame on a Button Click Event
    $("#myButton").click(function(event){
        $("#myIFrame").attr('src', prefix + $('#url').val());
    });
});


Am I not thinking correctly, or you just need the:

$("#myIFrame").attr('src', 'script.php?param=' + $('#url').val());
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜