简体   繁体   English

使用脚本插入jQuery以更改元素

[英]Insert jQuery with script to change elements

I am inserting HTML into my webpage and want to change some of the elements with jQuery. 我正在将HTML插入网页,并希望使用jQuery更改某些元素。 The file is being read every second and this is the element that I want to change: 每秒读取一次文件,这是我要更改的元素:

<div id="progress" class="progress-bar progress-bar-info progress-bar-striped" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: 20%">

I tried the following (didn't work): 我尝试了以下操作(无效):

<script>
function change(){ $("#progress").attr('aria-valuenow', '60'); 
};
change();
</script>

I also tried this (didn't work): 我也试过了(没用):

<script>
function change(){ $("#progress").attr('aria-valuenow', '60'); }; change();
</script>

The website is definitely reading properly from the file, and it is probably just the way that I am inserting the code that doesn't make the change. 该网站绝对可以从文件中正确读取数据,这可能只是我插入无法进行更改的代码的方式。

Help please. 请帮助。

PS I am re-reading the file that inputs the HTML with the following AJAX call. PS我正在重新读取通过以下AJAX调用输入HTML的文件。 Basically it just re-reads the file every second and appends html to a div: 基本上,它只是每秒重新读取文件,并将html附加到div:

<script>
$(document).ready(function() {
    var filename = "path/to/file/" + fileName;
    console.log(filename);
    setTimeout(functionToLoadFile, 10);
    function functionToLoadFile(){
            $.ajax({
                url: filename,
                cache: false,
                success: function(data) {
                    $('#content').html(data);
                    setTimeout(functionToLoadFile, 1000);
                },
            });
    }
});
</script>

Thanks to everyone who responds <3 感谢所有回应<3

Try this jsfiddle 试试这个jsfiddle

Basically: 基本上:

$("#progress").progressbar("option", "value", 60);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM