4

以下是问题的概要:

console.log($("#clippy")); //For testing purposes. The element is properly selected.

//Next, I need to grab the text value I want to be copied into the clipboard...
var textToCopy = $(".permalink input[name='link']").text();

//How can I paste the value inside textToCopy inside the appropriate areas:
//Here's the exact HTML I need to manipulate, with the two params I need to modify.
//Labeled: "<-----HERE!"

/*<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
        width="110"
        height="25"
        id="clippy" >
    <param name="movie" value="/flash/clippy.swf"/>
    <param name="allowScriptAccess" value="always" />
    <param name="quality" value="high" />
    <param name="scale" value="noscale" />
    <param NAME="FlashVars" value="text=sergio is the best champ"> <-------HERE!
    <param name="bgcolor" value="#fff">
    <embed src="../../Public/javascripts/clippy.swf"
            width="110"
            height="25"
            name="clippy"
            quality="high"
            allowScriptAccess="always"
            type="application/x-shockwave-flash"
            pluginspage="http://www.macromedia.com/go/getflashplayer"
            FlashVars="text=sergio is the best champ" <--------AND HERE!
            bgcolor="#fff"
    />
</object>*/

假设 的值为textToCopy“Welcome to The Matrix.”,这将是生成的 HTML:

 /*<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
        width="110"
        height="25"
        id="clippy" >
    <param name="movie" value="/flash/clippy.swf"/>
    <param name="allowScriptAccess" value="always" />
    <param name="quality" value="high" />
    <param name="scale" value="noscale" />
    <param NAME="FlashVars" value="text=Welcome to The Matrix."> <-------HERE!
    <param name="bgcolor" value="#fff">
    <embed src="../../Public/javascripts/clippy.swf"
            width="110"
            height="25"
            name="clippy"
            quality="high"
            allowScriptAccess="always"
            type="application/x-shockwave-flash"
            pluginspage="http://www.macromedia.com/go/getflashplayer"
            FlashVars="text=Welcome to The Matrix." <--------AND HERE!
            bgcolor="#fff"
    />
</object>*/
4

1 回答 1

6

您可以通过按名称查找参数来访问对象的参数:

$('#clippy').find('param[name="FlashVars"]').val(textToCopy); 

您可以像这样访问对象中嵌入的属性:

$('#clippy').find('embed').attr('FlashVars', textToCopy);
于 2012-04-27T21:11:11.977 回答