3

jQuery スクリプトで、クリックされたリンクから URL を取得し、ビデオ タグに挿入しようとしています。何かアドバイス?

.html() から取得したものをつなぎ合わせようとしましたが、引用符は常にそれを台無しにします。

<div class="binShadow">
        <div class="bin">       
            <table id="tableBin" border="0">
                <tr>
                    <th>name</th>
                    <th>description</th>
                    <th>location</th>
                    <th>duration</th>
                </tr>
                <tbody>
                    <tr>
                        <td><a href='clip1234.mov'>Clip1234</a></td>
                        <td>dolor sit amet, consectetur adipiscing elit</td>
                        <td>dr101</td>
                        <td>:60</td>
                    </tr>
                    <tr>
                        <td><a href="clip456.mov">Clip456</a></td>
                        <td>Lorem ipsum dolor sit amet</td>
                        <td>dr101</td>
                        <td>:60</td>
                    </tr>
                </tbody>
                </div>
            </table>
        </div>
    </div>  
</div>
<script>
    $("#tableBin").click(function () {
            var url = $(this).html(); //Not even close to working
            var overlay = jQuery('<div class="boxWrapper"><div class="box"><video src="'+url+'"</div></div>');

            overlay.appendTo(document.body);
    });
</script>

ステートメントが値を評価し、属性なしでフォーム フィールドを出力する0ため、値が の場合、フォーム フィールドは再入力されません。ifFALSEvalue

だから、if発言はやめてください。代わりにこれが必要です:

<input id="age" name="age" type="text" value="<?=set_value('age')?>" />

set_value()値が指定されている場合は値を返し、値が指定されていない場合はデフォルト値または空の文字列を返します。

4

3 に答える 3

4

hrefクリックのコンテキストから直接プルできます。

$("#tableBin").on("click", "a", function(e){
  e.preventDefault();
  url = this.href;
});
于 2012-04-25T16:07:47.943 に答える
2

ここに行く:

$("#tableBin a").on("click", function(e) {
 e.preventDefault();
 var url = $(this).attr("href");
 var overlay = jQuery('<div class="boxWrapper"><div class="box"><video src="'+url+'"</div></div>');

 overlay.appendTo(document.body);
});
于 2012-04-25T16:07:49.633 に答える
0

var url = $(this).html();内に含まれるhtmlを含む文字列を提供します

<a href="...">...</a>タグ。あなたの場合、それは次のようになりますClip1234

href属性を読み取りたい。

var url = this.href; //Plain old Javascript, not jQuery
于 2012-04-25T16:09:29.253 に答える