gpt4 book ai didi

javascript - 按编辑器按钮时不显示预览选项卡

转载 作者:行者123 更新时间:2023-11-28 18:05:31 27 4
gpt4 key购买 nike

当我在文本区域中输入内容时,一旦检测到超过 4 个字符,就会启用预览选项卡。

如果我点击编辑器按钮示例,按钮粗体会显示类似 **strong text** 的文本,但即使有超过 4 个字符的预览选项卡也不会启用。

目前仅在 keyup 时启用

Question: How can I make sure if I click on a editor button it will dected how many characters and if greater than 4 will enable tab.

CodePen Example Demo

$('#tab-preview').hide();

$("#textarea_message").on('keyup', function(e){
if ($(this).val().length >= "4") {
$('#tab-preview').show();
}

if ($(this).val().length < "4") {
$('#tab-preview').hide();
}
});

HTML

<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<form id="form-ask">

<div class="form-group">
<button type="button" id="button-bold" class="btn btn-default" title="Bold"><i class="fa fa-bold" aria-hidden="true"></i></button>
<button type="button" id="button-italic" class="btn btn-default" title="Italic"><i class="fa fa-italic" aria-hidden="true"></i></button>
<button type="button" id="button-quote" class="btn btn-default" title="Quote"><i class="fa fa-quote-left" aria-hidden="true"></i></button>
<button type="button" id="button-code" class="btn btn-default" title="Code"><i class="fa fa-quote-left" aria-hidden="true"></i></button>
<button type="button" id="button-insert-image" data-toggle="modal" data-target="#insert-image" class="btn btn-default" title="Insert Image URL"><i class="fa fa-code" aria-hidden="true"></i>
</button>
<button type="button" id="button-upload" class="btn btn-default" title="Add Attachment: This can be image or file "><i class="fa fa-file" aria-hidden="true"></i>
Attach File</button>
</div>

<div class="panel ask panel-default">
<div class="panel-heading">
<ul class="nav nav-tabs">
<li class="active"><a data-target="#ask" id="tab-ask" data-toggle="tab"><i class="fa fa-code" aria-hidden="true"></i> Ask Question</a></li>
<li><a data-target="#preview" id="tab-preview" data-toggle="tab"><i class="fa fa-eye" aria-hidden="true"></i> Preview</a></li>
</ul>
</div>
<div class="panel-body">
<div class="tab-content">
<div class="tab-pane fade in active" id="ask">
<div class="form-group">
<textarea id="textarea_message" class="form-control"></textarea>
</div>
</div>
<div class="tab-pane fade" id="preview">
<div class="preview-message"></div>
</div>
</div>
</div>
</div>
<p class="text-muted">Preview Button will be enabled once your question has reached
4 character or more.</p>


</form>
</div>
</div>
</div>

最佳答案

一种解决方案是为按钮上的 keyup 事件添加“触发器”

$('#button-bold').on('click', function(e) {
markdown_syntax(this.id, "**", "**", 'strong text');
$("#textarea_message").trigger('keyup');
});

关于javascript - 按编辑器按钮时不显示预览选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42745135/

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