gpt4 book ai didi

javascript - 输入数据到可拖动不起作用

转载 作者:行者123 更新时间:2023-12-03 06:56:13 25 4
gpt4 key购买 nike

我做错了什么,请帮忙,一个输入不起作用,请尝试一下,我希望能够在两个输入上写入并在可拖动的情况下显示每个输入,我已经在这个问题上坚持了一整天,试图弄清楚

$(function() {
$( "#draggable" ).draggable();
});
$("#get").click(function () {

$('#msg').html($('input:text').val());

});

$(function() {
$( "#draggable" ).draggable();
});
$("#get1").click(function () {

$('#msg1').html($('input:text').val());

});
<style>#draggable { width: 150px; height: 150px; border: none;padding: none; background: transparent; }

.container {
width: 500px;
height: 500px;
border: 2px solid;
position: relative;
overflow: auto;
}
</style>
<input id="fid" type='text'><button id='get'>Get</button>
<input id="fid1" type='text'><button id='get1'>Get</button>

<div class="container">
<div id="draggable" class="ui-widget-content"> <span id='msg'></span></div>

<div id="draggable" class="ui-widget-content"> <span id='msg1'></span></div>
</div><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>UI widget</title><link rel="stylesheet"
href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<link rel="stylesheet"
href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>

<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<link rel="stylesheet" href="/resources/demos/style.css">

最佳答案

当您有输入的 Id 时,您可以直接使用它..并且您的 Id 应该是唯一的..所以不要重复 id="draggable" 尝试使用 draggable1 , draggable2

$(function() {
$( "#draggable1" ).draggable();
$( "#draggable2" ).draggable();
$("#get").click(function () {
$('#msg').html($('#fid').val());
});
$("#get1").click(function () {
$('#msg1').html($('#fid1').val());
});
});
<style>#draggable { width: 150px; height: 150px; border: none;padding: none; background: transparent; }

.container {
width: 500px;
height: 500px;
border: 2px solid;
position: relative;
overflow: auto;
}
</style>
<input id="fid" type='text'><button id='get'>Get</button>
<input id="fid1" type='text'><button id='get1'>Get</button>

<div class="container">
<div id="draggable1" class="ui-widget-content"> <span id='msg'></span></div>

<div id="draggable2" class="ui-widget-content"> <span id='msg1'></span></div>
</div><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>UI widget</title><link rel="stylesheet"
href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<link rel="stylesheet"
href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>

<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<link rel="stylesheet" href="/resources/demos/style.css">

如果您需要附加输出,则需要使用 .append() 而不是 .html() .. 像这样

$(function() {
$( "#draggable1" ).draggable();
$( "#draggable2" ).draggable();
$("#get").click(function () {
$('#msg').append($('#fid').val());
});
$("#get1").click(function () {
$('#msg1').append($('#fid1').val());
});
});
<style>#draggable { width: 150px; height: 150px; border: none;padding: none; background: transparent; }

.container {
width: 500px;
height: 500px;
border: 2px solid;
position: relative;
overflow: auto;
}
</style>
<input id="fid" type='text'><button id='get'>Get</button>
<input id="fid1" type='text'><button id='get1'>Get</button>

<div class="container">
<div id="draggable1" class="ui-widget-content"> <span id='msg'></span></div>

<div id="draggable2" class="ui-widget-content"> <span id='msg1'></span></div>
</div><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>UI widget</title><link rel="stylesheet"
href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<link rel="stylesheet"
href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>

<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<link rel="stylesheet" href="/resources/demos/style.css">

关于javascript - 输入数据到可拖动不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37263781/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com