第一次存储变量时,它是未定义的,每隔一次它工作时?使用Jquery、Javascript和Ajax
这是函数的一部分: 我认为问题就在这里。如果需要的话,我会把整件事发出去 基本上,第一次存储var editid时,它是一个未定义的值 变量被发送到一个PHP页面,我让它在页面上回显结果 毫无疑问,它第一次存储其值onclick是未定义的,每隔一次存储适当的值 以下是全部内容:第一次存储变量时,它是未定义的,每隔一次它工作时?使用Jquery、Javascript和Ajax,javascript,jquery,ajax,javascript-events,Javascript,Jquery,Ajax,Javascript Events,这是函数的一部分: 我认为问题就在这里。如果需要的话,我会把整件事发出去 基本上,第一次存储var editid时,它是一个未定义的值 变量被发送到一个PHP页面,我让它在页面上回显结果 毫无疑问,它第一次存储其值onclick是未定义的,每隔一次存储适当的值 以下是全部内容: <script> $(document).ready(function(){ var $currentInput = null; $("#border_button, #background_color_
<script>
$(document).ready(function(){
var $currentInput = null;
$("#border_button, #background_color_button, #opacity_button").click(function() {
if ($currentInput == null) {
$currentInput = $(this).prev();
$("label").html($currentInput.attr("id"));
}
});
var editid;
$("div.editable").click(function(e) {
if ($currentInput == null)
return;
var css = GetCssProperties();
$(this).css(css);
editid = $(this).attr("id");
$currentInput = null;
$("label").html("");
});
function GetCssProperties() {
if ($currentInput == null) return null;
var value = $currentInput.val();
if ($currentInput.attr("id") == "background-color") {
ajaxStyle(value, 1, editid)
return {
"background-color": value
}
}
if ($currentInput.attr("id") == "border-radius") {
ajaxStyle(value, 2, editid)
return {
"border-radius": value
}
}
if ($currentInput.attr("id") == "opacity") {
ajaxStyle(value, 3, editid)
return {
"opacity": value
}
}
}
});
在设置变量值之前调用GetCssProperties。 如果您试图在GetCssProperties中访问该变量,那么这将是第一次未定义该变量,因为您已经全局声明了它,但它仍然没有值 将顺序更改为:
editid = $(this).attr("id");
var css = GetCssProperties();
你有现场演示,我们可以看,或玩吗?也许是这样,只是为了复制这个问题。似乎您试图将PHP变量约定实现为javascript-$I可以将其放在JS FIDLE上,但它使用PHP。我将添加整个函数,如果您希望$currentinput中的变量来自PHP,还是javascript中的全局变量?currentinput来自HTML输入边框半径背景OpacityFantastic!我不敢相信我忽略了这一点。非常感谢你!
editid = $(this).attr("id");
var css = GetCssProperties();