无法使用jQuery

时间:2017-07-11 20:47:58

标签: javascript jquery html

我试图保存" src"的价值。在.txt文件中,该文件位于C:\hi\data.txt的本地光盘上。

我认为问题出在id: $(this).find('.src').val(),因为src是在某个JS的帮助下点击按钮后创建的。

我对jQuery和JS并不完全熟悉,但这是我设法做到的。 "添加视频"按钮工作正常。

<body>

<input id="input" type="text" name="Youtube Source" />
<button id="button" onclick="addVideo();">Click to add video!</button>
<button id="button1">Click to save!</button>

<div id="ytContainer"></div>

</body>

<script>
var x;
function addVideo() {
    x = document.createElement("EMBED");
    x.setAttribute("src", 'https://www.youtube.com/v/' + input.value);
    document.getElementById("ytContainer").appendChild(x);
}
</script>

<script>
$("#button1").click(function ()
{
    $('#form_addjts').submit(function () {
        writeToFile({
            id: $(this).find('.src').val(),
        });
        return false;
    });
    function writeToFile(data) {
        var fso = new ActiveXObject("Scripting.FileSystemObject");
        var fh = fso.OpenTextFile("C:\hi\data.txt", 8);
        fh.WriteLine(data.src);
        fh.Close();
    }
});
</script>

1 个答案:

答案 0 :(得分:0)

如果src的值没有说明问题,那么示例中没有带“src”类的元素。 如果你在谈论embed src,你可以$('#ytContainer').find('embed').attr('src'); 如果确实有一个带有“src”类的元素,我们在表格中看不到,我们也看不到,那么问题可能就是其他问题。

相关问题