1
CORRECTIONSのために働いていないボタンを提出ツリービューメッセージボードは - 私は親メッセージと子メッセージを持っている(会話ツリーのような)メッセージボードを持っている...子供BELOW MADE
を無効にします。私は何も入力ボックスに入力されていないときに送信ボタンを無効にする下のjqueryを実装しました。それは親のサブミットボタン(#sendcomment入力ボックス)では動作しますが、子(#sendcomment入力ボックスも)では動作しません。何か案は?
<div id="defaultcontainerwrapper" class="maxwidth">
<div class="messageList" style="margin-top:10px; margin-left:30px;">
<?php foreach($this->messageList as $k=>$message){
$postId=$message['postId'];
if($message['depth']!=0){
$depth=$message['depth'];
do{
echo(": . . ");
$depth--;
}
while($depth!=0);
}
?>
<span class="viewThread">
<a style="color:#cd6b2e;text-decoration:underline; cursor:pointer; cursor: hand;"
onclick="<?php echo "javascript:ajaxView(" . $postId . ");"; ?>"><?php echo $message['content'] ? nl2br(substr($message['content'], 0, 30)) . '...' : ''; ?></a>
<?php echo htmlspecialchars("<");?><a style="color:grey;"><?php echo $message['posterName'];?></a><?php echo htmlspecialchars(">")." ".$message['date']."<br/>\n";?>
</span>
<div class="displayPanel" id="<?php echo $postId;?>" >
<div class="displayContent" >
</div>
<div class="RepForm-loggedin" >
<form name="RepForm" method="POST" action="<?php echo $this->newReply;?>">
<table name="RepFormTable" style="width:100%">
<script type="text/javascript" src="data/js/jquery_lib/jquery.min.js"></script>
<tr>
<td style="width:100%">
<input type="text" maxlength="75" id="repContent" class="inputbox inputbox-title placeholder-soc-med"
name="repContent" placeholder="Add your comment here. . ."/>
<span><input type="submit" id="sendComment" name="sendComment" class="dgrey-button cancel-button" value="Submit"></span>
</td>
</tr>
</table>
<textarea style="display: none" name="content"></textarea>
<input type="hidden" value="<?php echo $this->tag ;?>" name="tag">
<input type="hidden" value="" name="parentId">
<input type="hidden" value="" name="depth">
</form>
</div>
</div>
<?php } ?>
<div class="clear"></div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
var sendComment = document.getElementsByName("sendComment");
var repContent = document.getElementsByName("repContent");
$(sendComment).attr('disabled', true);
$(repContent).keyup(function() {
if ($(this).val().length != 0)
$(sendComment).attr('disabled', false);
else
$(sendComment).attr('disabled', true);
})
});
<script>
がID #sendCommentを再利用問題になる可能性が含まれているすべての要素を照会するセレクタ
$("[id*=sendComment]")
を使用し、その後、id="sendComment-<?php echo $postId; ?>"
など、親メッセージIDを追加することができたい場合。 id属性はページごとに一意であることを意図しています –ありがとう、@ RyanTuosto。それが問題を解決しました。 – ian
@RyanTuosto私の解決策は、name = "sendComment"を入力に追加することでした。次に、document.getElementsByName( "sendComment")を使用して名前を参照しました。魅力のように働いた。上記の訂正。再度、感謝します。 – ian