【问题标题】:Changing the value of a bootstrap component dynamically动态更改引导组件的值
【发布时间】:2018-10-19 08:42:36
【问题描述】:

我正在尝试更改将在按钮单击事件上更改的引导组件中的值

这是我的组件。它是一个小条,根据通过标记代码输入的值填充到一定百分比

<div class="progress">
 <div id="theprogressbar" class ="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="95" aria-valuemin="0" aria-valuemax="100" 
style="width: 95%">
  <span class="sr-only">95% Complete</span>
    </div>
 </div>

style="width: 95%" 是需要更改才能更改条形填充百分比。以下是引导组件的示例 我将如何更改按钮单击事件中的百分比值?提前感谢,如果我看起来含糊不清,对不起! c# 是我正在使用的编码语言,这是在网络表单上进行的

更新:JQUERY 代码

<script>


$('#btnSave').click(function () {
    $.ajax({

    url: 'http://localhost:61417/ProjectMainMenu/GetProgress',
    method: 'POST',
    contentType: 'application/json',
    success: function(response){
        var progressValue=response.d;
        $('#theprogressbar').attr('aria-valuenow', progressValue).css('width',progressValue);
        $("#progressValue").text(progressValue);
    }
        });

     </script>

C#代码

      [WebMethod]
public static double GetProgress()
{
     double progress=0;
     //Your Business Logic
     progress=56;
     return progress;
}

按钮标记代码

<asp:Button ID="btnSave" width =" 250px" runat="server" Text="View"  class="btn btn-info" />

【问题讨论】:

  • 实际上非常模糊...您可能需要编写一些 JavaScript 代码来更新它。
  • 抱歉,我尝试更新它以使其更易于理解
  • 我也认为您最终会为此使用 Javascript。不要忘记更新 aria-valuenow 属性以保持可访问性。
  • 请参考so question and answer。希望能解决您的问题。

标签: c# asp.net webforms bootstrap-4


【解决方案1】:

您需要使用作为 Web 服务方法工作的 WebMethod 属性。

HTML & Jquery

<div class="progress">
     <div id="theprogressbar" class="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="95" aria-valuemin="0" aria-valuemax="100" style="width: 95%">
     <span class="sr-only"><span id="progressValue">95</span>% Complete</span>
   </div>
</div>

<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js">

<script>
     $(document).ready(function(){
        $('#btnSave').click(function () {
          $.ajax({
            url: 'http://localhost:56894/Progress.aspx/GetProgress',
            method: 'POST',
            contentType: 'application/json',
            success: function(response){
                var progressValue=response.d;
                $('#theprogressbar').attr('aria-valuenow', progressValue).css('width',progressValue);
                $("#progressValue").text(progressValue);
            }
       });
    });
</script>

ASP.NET 网络表单

[WebMethod]
public static double GetProgress()
{
     double progress=0;
     //Your Business Logic
     progress=56;
     return progress;
}

Javascript

【讨论】:

  • 问的问题是指网络表单,所以我的 API 控制器在这种情况下不起作用
  • 试过了,它不起作用,我已经更改了值以匹配我自己的值。该按钮名为 btnSave,我已更改 url 以匹配我的 url。有什么想法吗?
  • btn 点击事件也没有触发
  • @GenericOverweightProgrammer 请检查您的 jquery 是否正常工作,您只需调用 alert(0);在点击事件下。
  • 正如@peeebeee 所提到的,“现在的价值”需要更新,无论如何要实现它
猜你喜欢
  • 2017-04-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-24
  • 2021-12-18
  • 1970-01-01
  • 2014-02-06
  • 1970-01-01
相关资源
最近更新 更多