简体   繁体   English

此代码中是否缺少用于弹出物化数据的函数?

[英]Is there any missing functions in this code to pop-up the materialize data?

The materialize pop-up does not appear.实体化弹出窗口不会出现。

$(document).ready(function() {
  $('#cdn_customer_id').on('click', function() {
    //alert("hi00");
    var countCust = '<?php count($customers) ?>';
    if (countCust < 1) {
      Materialize.toast('Add a Sales/Client Master', 3000, 'red rounded')
    }
  });
<select class="js-example-basic-single" name="cust_id" id="cdn_customer_id">
  <option value="">SELECT CLIENT</option>
  <?php foreach ($customers as $cus) { ?>
    <option value="<?php echo $cus->cust_id; ?>" <?php if(!empty($inv)){if($inv[0]->cust_id!=0){ echo ($inv[0]->cust_id==$cus->cust_id)?'selected':''; }} ?> >
    <?php echo strtoupper($cus->cust_name); ?>
  </option>
  <?php } ?>
</select>

Try the following尝试以下

There's two changes I'd make to your code from what I can see, I don't know if it will fix everything but from the information you've given us, this is the best I can come up with.根据我所看到的,我会对您的代码进行两项更改,我不知道它是否会解决所有问题,但从您提供给我们的信息来看,这是我能想到的最好的方法。


First Issue:首要问题:

You are setting an on click listener on a drop-down, surely you want this to fire when someone selects an option, not when they click on the select, I'd change the following line:您正在下拉列表中设置click侦听器,当然您希望在有人选择选项时触发它,而不是在他们单击选择时触发,我会更改以下行:

$('#cdn_customer_id').on('click', function() {

To a change listener by simply changing the word click :只需更改单词click即可change侦听器:

$('#cdn_customer_id').on('change', function() {

Second Issue:第二期:

I don't think the customer count is being set properly, you haven't used echo to output a value, it's not best practice to place a PHP value in JavaScript but seeing as you've done this and I have limited information available to change it, we'll leave it as it is but actually set the value properly by changing the following line:我认为客户数量设置不正确,您还没有使用echo来输出值,在 JavaScript 中放置 PHP 值不是最佳实践,但是看到您已经完成了此操作,我可提供的信息有限更改它,我们将保持原样,但实际上通过更改以下行来正确设置值:

var countCust = '<?php count($customers) ?>';

To echo the value using the short-hand version, providing you are using PHP 5.4 or later, this shouldn't be an issue:如果您使用的是PHP 5.4或更高版本,要使用简写版本回显值,这应该不是问题:

var countCust = '<?=count($customers) ?>';

However, if for some reason you're using an earlier version of PHP I might as well include the longer version:但是,如果由于某种原因您使用的是早期版本的 PHP,我不妨包含更长的版本:

var countCust = '<?php echo count($customers) ?>';

I'd say if you make these two changes, see if anything improves and get back to me with your feedback and hopefully solve the next issue if there is one.我想说的是,如果您进行这两个更改,请查看是否有任何改进,然后将您的反馈反馈给我,并希望解决下一个问题(如果有的话)。

It looks like this is a materializecss specific question.看起来这是一个materializecss特定问题。

Your markup looks wrong for one.你的标记看起来不对。 The docs use this structure:文档使用此结构:

M.toast({html:'Add a Sales/Client Master'})

Codepen here .代码笔在这里

So an object inside the toast.所以吐司里面的一个对象。 Not sure why you are passing other style data in.不知道为什么要传入其他样式数据。

Another way is to declare the html first, then pass it in. From the docs:另一种方法是先声明 html,然后将其传入。从文档中:

 var toastHTML = '<span>I am toast content</span><button class="btn-flat toast-action">Undo</button>';
  M.toast({html: toastHTML});

https://materializecss.com/toasts.html https://materializecss.com/toasts.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM