gpt4 book ai didi

javascript - 这个 javascript 没有从数据库动态获取数据有什么问题?

转载 作者:行者123 更新时间:2023-12-03 04:52:20 24 4
gpt4 key购买 nike

我在许多其他不同的页面上有相同的脚本和相同的样式,并且它非常适合在模式中显示动态数据。我从上到下剥离了脚本...我已经重写了很多次,但我看不到发生了什么...模式打开但没有显示数据。

动态数据

 <tbody>
<?php while($client=mysqli_fetch_array($resultclient)){ ?>
<tr>
<td data-th="ID" sorttable_customkey="2">
<button title="Edit Client" type='button' class='btn btn-default btn-sm' data-toggle='modal' data-target='#editClient'
data-clientId="<?=$client['id'];?>"
data-clientWebsite="<?=$client['company_url'];?>"
data-clientEmail="<?=$client['contact_email'];?>"
data-clientSecretid="<?=$client['secret_id'];?>"
data-clientName="<?=$client['name'];?>"
data-clientStatus="<?=$client['client_status'];?>"
data-clientIndustry="<?=$client['client_industry'];?>"
data-clientAddress="<?=$client['address'];?>"
data-clientContactName="<?=$client['contact_name'];?>"
data-clientContactNumber="<?=$client['contact_number'];?>">
<i class="fa fa-pencil-square-o" aria-hidden="true"></i>
</button>
</td>
</tr>
<?php };?>
</tbody>

在模态中显示

<input id="clientid" class="form-control formBlock" type="hidden" value="">
<input id="clientsecretid" class="form-control formBlock" type="hidden" value="">
<input id="clientname" class="form-control formBlock" type="text" value="" readonly>
<input id="clientstatus" class="form-control formBlock" type="text" value="" readonly>
<input id="clientindustry" type="text" class="formBlock form-control" value="" readonly/>
<input id="clientaddress" type="text" class="formBlock form-control" value="" readonly/>
<input id="clientcontactname" type="text" class="formBlock form-control" value="" readonly/>
<input id="clientcontactnumber" type="text" class="formBlock form-control" value="" readonly/>
<input id="clientwebsite" type="text" class="formBlock form-control" value="" readonly/>
<input id="clientemail" type="text" class="formBlock form-control" value="" readonly/>

脚本

$(document).ready(function () {
$('#editClient').on('show.bs.modal', function (client) { // id of the modal with event
var button = $(client.relatedTarget); // Button that triggered the modal

//get dynamic data from button data-attributes
var clientId = button.data('clientId'); // Extract info from data-* attributes
var clientSecretid = button.data('clientSecretid');
var clientName = button.data('clientName');
var clientStatus = button.data('clientStatus');
var clientIndustry = button.data('clientIndustry');
var clientAddress = button.data('clientAddress');
var clientContactName = button.data('clientContactName');
var clientContactNumber = button.data('clientContactNumber');
var clientWebsite = button.data('clientWebsite');
var clientEmail = button.data('clientEmail');

//display data in modal
var modal = $(this);
modal.find('#clientid').val(clientId);
modal.find('#clientsecretid').val(clientSecretid);
modal.find('#clientname').val(clientName);
modal.find('#clientstatus').val(clientStatus);
modal.find('#clientindustry').val(clientIndustry);
modal.find('#clientaddress').val(clientAddress);
modal.find('#clientcontactname').val(clientContactName);
modal.find('#clientcontactnumber').val(clientContactNumber);
modal.find('#clientwebsite').val(clientWebsite);
modal.find('#clientemail').val(clientEmail);

});
});

最佳答案

您需要在数据调用中小写名称。

var clientId = button.data('clientid');
var clientSecretid = button.data('clientsecretid');
var clientName = button.data('clientname');
var clientStatus = button.data('clientstatus');
var clientIndustry = button.data('clientindustry');
var clientAddress = button.data('clientaddress');
var clientContactName = button.data('clientcontactname');
var clientContactNumber = button.data('clientcontactnumber');
var clientWebsite = button.data('clientwebsite');
var clientEmail = button.data('clientemail');

或像您一样正确格式化要调用的数据属性..

<button title="Edit Client" type='button' class='btn btn-default btn-sm'      data-toggle='modal' data-target='#editClient' 
data-client-id="<?=$client['id'];?>"
data-client-website="<?=$client['company_url'];?>"
data-client-email="<?=$client['contact_email'];?>"
data-client-secretid="<?=$client['secret_id'];?>"
data-client-name="<?=$client['name'];?>"
data-client-status="<?=$client['client_status'];?>"
data-client-industry="<?=$client['client_industry'];?>"
data-client-address="<?=$client['address'];?>"
data-client-contact-name="<?=$client['contact_name'];?>"
data-client-contact-number="<?=$client['contact_number'];?>">
<i class="fa fa-pencil-square-o" aria-hidden="true"></i>
</button>

这里有好东西:Using data attributes with jQuery

关于javascript - 这个 javascript 没有从数据库动态获取数据有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42604390/

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