yii 如何在onclick函数中传递3个参数?参数在php标签中

nx7onnlm  于 2022-11-09  发布在  PHP
关注(0)|答案(5)|浏览(152)

这是我的onclick函数:

onclick="InboxDetailsPage('<?php echo $message['id']; ?>')

这些是我的参数:threadidrecipient idmessage id

<input type="hidden" id="threadId-<?php echo $message['id']; ?>" value="<?php echo $message['threadId']; ?>"/>
<input type="hidden" id="recipientId-<?php echo $message['id']; ?>" value="<?php echo $message['otherUserRoleId']; ?>"/>
<?php echo $message['id']; ?>

这是我使用onclick函数的地方:

<div class="inbox">
    <?php $inboxno = 0;
    foreach ($messageList as $message) { ?>
        <?php if ($message['toFromLabel'] == "From") {
            $inboxno++; ?>
            <input type="hidden" id="threadId-<?php echo $message['id']; ?>" value="<?php echo $message['threadId']; ?>"/>
            <input type="hidden" id="recipientId-<?php echo $message['id']; ?>" value="<?php echo $message['otherUserRoleId']; ?>"/>
            <tr class="gradeA odd inbox">
                <td class="" style="padding-bottom: 1px;" <?php if ($message['status'] == MessageStatusEnum::UNREAD){ ?>style="color:#E55B43;" <?php } else { ?>style="color:#000;" <?php }; ?>><?php echo $message['date']; ?></td>
                <td class="" style="padding-bottom: 1px;" <?php if ($message['status'] == MessageStatusEnum::UNREAD){ ?>style="color:#E55B43;" <?php } else { ?>style="color:#000;" <?php }; ?>><?php echo $message['fromName']; ?></td>
                <td class=" " style="padding-bottom: 1px;" <?php if ($message['status'] == MessageStatusEnum::UNREAD){ ?>style="color:#E55B43;" <?php } else { ?>style="color:#000;" <?php }; ?> style="width:300px !important"><?php echo $message['subject'] ?></td>
                <td class="" style="padding-bottom: 1px;"><a type="button" data-toggle="modal" data-target="#myModalq1" class="btn btn-success " onclick="InboxDetailsPage('<?php echo $message['id']; ?>') ">VIEW</a></td>
            </tr>
        <?php }
    } ?>
</div>
eiee3dmh

eiee3dmh1#

你可以做下面的格式:

onclick="InboxDetailsPage('<?php echo $message['id'];?>', '<?php echo $message['id'];?>', '<?php echo $message['id'];?>')

或者,仅使用一个回波:

onclick="InboxDetailsPage(<?php echo "'{$message['id']}', '{$message['date']}', '{$message['id']}'";?>)
fnvucqvd

fnvucqvd2#

您可以使用此方法:

<a href="#" onclick="myFunction('parameter1', 'parameter', 'parameter3');">click me</a>
<script>
    function myFunction(parameter1, parameter2, parameter3) {
      alert(parameter1);
    }
</script>
kgsdhlau

kgsdhlau3#

onclick="InboxDetailsPage(
    '<?php echo $message['id'];?>', 
    '<?php echo $message['id'];?>', 
    '<?php echo $message['id'];?>'
)
hmmo2u0o

hmmo2u0o4#

另一个选择是对选项数组进行JSON编码,并发送参数,这样就避免了长参数列表,并更好地提高了可读性。

$params=[
   'thread_id'=>$message['thread_id'],
   'recipient_id'=>$message['recipient_id'],
   'id'=>$message['id']
];

<input type="text" onclick="InboxDetailsPage('<?=json_encode($params)?>')">

然后使用它

function InboxDetailsPage(options){
     console.log(options.thread_id,options.recipient_id,options.id);
}
h7wcgrx3

h7wcgrx35#

您可以尝试以下操作:

onclick="InboxDetailsPage("<?php echo $message['id'];?>","threadId-<?php echo $message['id']; ?>","recipientId-<?php echo $message['id']; ?>")

相关问题