使用greasemonkey编辑html

时间:2012-12-20 11:31:46

标签: javascript greasemonkey

我在html doc

中有这个文本
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="" id="movie" align="middle" height="371" width="495">
    <param name="movie" value="/play/skins/flash/22753/a.swf?
    movid=blfgbd&amp;clid=22753&amp;autoplay=true&amp;noad=&amp;
    did=1000806817&amp;&amp;cache_buster=634916059503671812&amp;session_id=806817&amp;
    break_number=0&amp;user_id=-1&amp;VAST=2&amp;is_hiro=true">
    <param name=...

我想将最后一个true更改为false is_hiro = true-&gt; is_hiro = false 我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

这应该有效:

// Get the <param> tag.
var param = document.getElementById('movie').children[0];
// Replace the content of the param's value.
param.value = param.value.replace('is_hiro=true', 'is_hiro=false');

请注意,这假设您的参数是该对象的第一个孩子 如果情况并非总是这样,那么最好给这个参数id

<param name="movie"
    id="myParameter"
    value="/play/skins/flash/22753/a.swf?
        movid=blfgbd&amp;clid=22753&amp;autoplay=true&amp;noad=&amp;
        did=1000806817&amp;&amp;cache_buster=634916059503671812&amp;
        session_id=806817&amp; break_number=0&amp;user_id=-1&amp;
        VAST=2&amp;is_hiro=true">
var param = document.getElementById('myParameter'); // Get the <param> tag.
param.value = param.value.replace('is_hiro=true', 'is_hiro=false');