【问题标题】:How can I open a datepicker with a label <button> </button> without using trigger?如何在不使用触发器的情况下打开带有标签 <button> </button> 的日期选择器?
【发布时间】:2020-04-13 23:46:26
【问题描述】:

我正在尝试改变按钮的工作方式。我希望&lt;input type = "submit"&gt; 的行为与&lt;button&gt; 在代码中的行为相同,而&lt;button&gt; 的行为与&lt;input type = "submit"&gt; 相同。如果我知道如何使用 &lt;button&gt; &lt;/button&gt; 标签打开日期选择器,我想我可以反转它。

<!DOCTYPE html>
<html>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.12.0/moment.js"></script>

<script type="text/javascript">

$(document).ready(function(){
    //type submit
    $( "#datepicker" ).datepicker();
    //type submit

    //Click buttom
    $("#div1").click(function() {
        $("#datepicker").datepicker("show");
    });
    //Click buttom
});
</script>

<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.css" rel="stylesheet"/>

<button id="div1" >13/04/2020</button>
<br>
<br>
<input type="submit" id="datepicker" value="CAMBIAR FECHA">
<!-- <input type="submit" id="open-datepicker" value="cambiar fecha"> -->
</body>
</html>

【问题讨论】:

  • 抱歉,不清楚您在问什么。
  • @Roamer-1888:如果感觉缺词...打开编辑模式;)
  • 如果你真的想要,你可以让一个按钮点击一个隐藏的&lt;input type="submit"&gt;。这会有帮助吗?
  • 欢迎来到 Stack Overflow。请看:api.jqueryui.com/datepicker/#option-showOn

标签: javascript jquery html css jquery-ui


【解决方案1】:

不清楚您遇到了什么问题或您想要完成什么。您可能需要考虑以下事项。

$(function() {
  $("#datepicker").datepicker({
    showOn: "button",
    buttonText: "13/04/2020"
  });
});
.back {
  background: #000;
  font-weight: 700;
  font-size: 50px;
  color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.12.0/moment.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.css" rel="stylesheet" />


<input type="submit" id="datepicker" value="CAMBIAR FECHA">

【讨论】:

  • 我遇到的问题是我不知道如何使
  • 您需要在input 上调整.val()
猜你喜欢
  • 1970-01-01
  • 2020-04-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-19
  • 2022-12-04
相关资源
最近更新 更多