Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 具有多个按钮的Elfinder filemanager更新文本输入_Javascript_Jquery_Ajax_Onclick - Fatal编程技术网

Javascript 具有多个按钮的Elfinder filemanager更新文本输入

Javascript 具有多个按钮的Elfinder filemanager更新文本输入,javascript,jquery,ajax,onclick,Javascript,Jquery,Ajax,Onclick,每个按钮都在更新元素: <input type="text" id="field" name="image" value="<?php echo @$DuzenleSonuc[0]['image']; ?>" /> 现在的情况与下面完全一样。我错在哪里 onclick open -> updates field onclick open1 -> updates field onclick open2 -> updates field o

每个按钮都在更新元素:

<input type="text" id="field" name="image" value="<?php echo @$DuzenleSonuc[0]['image']; ?>" />
现在的情况与下面完全一样。我错在哪里

  onclick open -> updates field
  onclick open1 -> updates field
  onclick open2 -> updates field
  onclick open3 -> updates field
  onclick open4 -> updates field
我的代码如下:

<script type="text/javascript" charset="utf-8">
    $().ready(function() {
        var opt = {// Must change variable name
            url : 'elfinder/connectors/php/connector.php',
            lang : 'tr',
            editorCallback : function(url) {document.getElementById('field').value=url;},// Must change the form field id
            closeOnEditorCallback : true,
            docked : false,
            dialog : { title : 'Dosya Yöneticisi', height: 500 },
        }

        $('#open').click(function() {// Must change the button's id
            $('#finder_browse').elfinder(opt)// Must update the form field id
            $('#finder_browse').elfinder($(this).attr('id')); // Must update the form field id
        })

        $('#open1').click(function() {// Must change the button's id
            $('#finder_browse1').elfinder(opt)// Must update the form field id
            $('#finder_browse1').elfinder($(this).attr('id')); // Must update the form field id
        })
        $('#open2').click(function() {// Must change the button's id
            $('#finder_browse2').elfinder(opt)// Must update the form field id
            $('#finder_browse2').elfinder($(this).attr('id')); // Must update the form field id
        })
        $('#open3').click(function() {// Must change the button's id
            $('#finder_browse3').elfinder(opt)// Must update the form field id
            $('#finder_browse3').elfinder($(this).attr('id')); // Must update the form field id
        })
        $('#open4').click(function() {// Must change the button's id
            $('#finder_browse4').elfinder(opt)// Must update the form field id
            $('#finder_browse4').elfinder($(this).attr('id')); // Must update the form field id
        })
    });
    $(document).ready(function(){
        $('.taslak').click(function(){
            $('#k').val("Taslak");
        });
    })
</script>
<!-- elFinder -->
<div class="textbox left">
    <h2>Ürün Resimleri</h2>

    <div class="textbox_content">
        <p class="fileupload">
            <label>Ürün Ana Resmi:</label>
        <div id="finder_browse"></div>
        <input type="text" id="field" name="image" value="<?php echo @$DuzenleSonuc[0]['image']; ?>" />
        <input type="button" id="open" class="file" value="Resim Seç" />
        </p>
        <hr />
        <p class="fileupload">
            <label>Ürün Resmi:</label>
        <div id="finder_browse1"></div>
        <input type="text" id="field1" name="image1" value="<?php echo @$DuzenleSonuc[0]['image1']; ?>" />
        <input type="button" id="open1" class="file" value="Resim Seç" />
        </p>
        <p class="fileupload">
            <label>Ürün Resmi:</label>
        <div id="finder_browse2"></div>
        <input type="text" id="field2" name="image2" value="<?php echo @$DuzenleSonuc[0]['image2']; ?>" />
        <input type="button" id="open2" class="file" value="Resim Seç" />
        </p>
        <p class="fileupload">
            <label>Ürün Resmi:</label>
        <div id="finder_browse3"></div>
        <input type="text" id="field3" name="image3" value="<?php echo @$DuzenleSonuc[0]['image3']; ?>" />
        <input type="button" id="open3" class="file" value="Resim Seç" />
        </p>
        <p class="fileupload">
            <label>Ürün Resmi:</label>
        <div id="finder_browse4"></div>
        <input type="text" id="field4" name="image4" value="<?php echo @$DuzenleSonuc[0]['image4']; ?>" />
        <input type="button" id="open4" class="file" value="Resim Seç" />
        </p>
    </div>
</div> 

$().ready(函数()){
var opt={//必须更改变量名
url:'elfinder/connectors/php/connector.php',
郎:"tr",,
editorCallback:function(url){document.getElementById('field')。value=url;},//必须更改表单字段id
CloseOneEdit或Callback:正确,
停靠:错误,
对话:{标题:'Dosya Yönetici',高度:500},
}
$(“#打开”)。单击(函数(){//必须更改按钮的id
$(“#finder_browse”).elfinder(opt)//必须更新表单字段id
$('#finder_browse').elfinder($(this.attr('id'));//必须更新表单字段id
})
$('#open1')。单击(函数(){//必须更改按钮的id
$('#finder_browse1')。elfinder(opt)//必须更新表单字段id
$('#finder_browse1').elfinder($(this.attr('id'));//必须更新表单字段id
})
$('#open2')。单击(函数(){//必须更改按钮的id
$('#finder_browse2')。elfinder(opt)//必须更新表单字段id
$('#finder_browse2').elfinder($(this.attr('id'));//必须更新表单字段id
})
$('#open3')。单击(function(){//必须更改按钮的id
$('#finder_browse3')。elfinder(opt)//必须更新表单字段id
$('#finder_browse3').elfinder($(this.attr('id'));//必须更新表单字段id
})
$('#open4')。单击(function(){//必须更改按钮的id
$('#finder_browse4')。elfinder(opt)//必须更新表单字段id
$('#finder_browse4').elfinder($(this.attr('id'));//必须更新表单字段id
})
});
$(文档).ready(函数(){
$('.taslak')。单击(函数(){
$('k').val(“塔斯拉克”);
});
})
Ürün Resimleri

Ürün Ana Resmi:


将同一类添加到所有按钮,并仅添加一次单击事件,如:

$('.btnClass').click(function(){
var btnID = $(this).attr('id'); // Btn id clicked
// Process ckick event
});
或者,如果所有按钮都打开了起始id,则可以创建一个单击事件,如

$('input[id^=open]').click(function(){    var btnID = $(this).attr('id'); // Btn id clicked});
在你的评论之后添加 获得btnID后,您可以找到要浏览的查找程序,如:

var $browser;
switch(btID)
{
case 'open':
$browser = $('#finder_browse');
break;case 'open1':
$browser = $('#finder_browse1');
break;
等等。。
}

我这样更改了代码,但仍然有相同的问题$点击(function(){var btnID=$(this).attr('id');//必须更改按钮的id$('finder_-browse')。elfinder(opt)//必须更新表单字段id$('finder_-browse')。elfinder($(btnID).attr('id');//必须更新表单字段id})我不理解你的评论,但根据您的代码,您可以编写如下代码:switch(btnID)
var $browser;
switch(btID)
{
case 'open':
$browser = $('#finder_browse');
break;case 'open1':
$browser = $('#finder_browse1');
break;