我的页面上有一个加载器,其html如下所示:
data-progress-text
我想编写一个可以在data-progress is 50
时更改"Loading 50 / 100"
的JS
来自"Almost there!"
到if ( $('.pace-progress').attr('data-progress-text') == '50' ) {
(".pace-progress").attr("data-progress-text") == "Almost there!"}
。
我不知道从哪里开始,我们将非常感谢任何帮助。
<%= form_for(@match_rules) do |f| %>
<%= f.label :name, "Name" %>
<%= f.text_field :name, placeholder: "Rule Set Name" %>
<%= f.label :algorithm, "Choose an algorithm" %>
<%= f.select :algorithm, build_algorithm_select_options %>
<%= f.label :match_fields, "Available fields" %>
<%= f.check_box :name, { checked: @match_rules.match_fields.include?("name") } %>
<%= f.label :name, "Name" %><br/>
<%= f.check_box :email, { checked: @match_rules.match_fields.include?("email") } %>
<%= f.label :email, "Email" %><br/>
<%= f.check_box :phone, { checked: @match_rules.match_fields.include?("phone") } %>
<%= f.label :phone, "Phone" %><br/>
<%= f.check_box :gender, { checked: @match_rules.match_fields.include?("gender") } %>
<%= f.label :gender, "Gender" %><br/>
<%= f.check_box :marital_status, { checked: @match_rules.match_fields.include?("marital_status") } %>
<%= f.label :marital_status, "Marital Status" %><br/>
<%= f.check_box :dob, { checked: @match_rules.match_fields.include?("dob") } %>
<%= f.label :dob, "Date of Birth" %><br/>
<%= f.check_box :campus, { checked: @match_rules.match_fields.include?("campus") } %>
<%= f.label :campus, "Campus" %><br/>
<%= f.check_box :address, { checked: @match_rules.match_fields.include?("address") } %>
<%= f.label :address, "Street Address" %><br/>
<%= f.check_box :city, { checked: @match_rules.match_fields.include?("city") } %>
<%= f.label :city, "City" %><br/>
<%= f.check_box :state, { checked: @match_rules.match_fields.include?("state") } %>
<%= f.label :state, "State" %><br/>
<%= f.check_box :zip, { checked: @match_rules.match_fields.include?("zip") } %>
<%= f.label :zip, "Zip Code" %><br/>
<%= f.submit "Save", class: "button primary" %>
<%= link_to "Cancel", match_rule_index_path, class: "button" %>
答案 0 :(得分:0)
==
用于比较值
=
用于分配值
也就是说,由于您使用的是jQuery attr
方法,因此无法分配这样的值。该方法本身接受第二个参数来确定它是getter还是setter。
jQuery docs非常完整,在提问之前你一定要充分利用它们
答案 1 :(得分:0)
使用setInterval定期检查值并更新相应的属性:
setInterval(fucntion(){
if ( $('.pace-progress').attr('data-progress') == '50' )
$(".pace-progress").attr("data-progress-text", "Almost there!");
}, 500);