Javascript 仅在注释中显示链接的短部分
如果用户在注释中插入了链接,则需要将此链接缩短到20个字符 怎么做 例如:Javascript 仅在注释中显示链接的短部分,javascript,ruby-on-rails,ruby-on-rails-4,Javascript,Ruby On Rails,Ruby On Rails 4,如果用户在注释中插入了链接,则需要将此链接缩短到20个字符 怎么做 例如: Lorem ipsum: https://github.com/plataformatec/devise 结果会是这样的 Lorem ipsum: https://github.com/plataforma... 要输出被截断的文本,可以使用内置的字符串功能 <%= link[0..19] %> 如果您希望将其作为链接的一部分,但希望导航上的完整链接,可能类似于: <%= link_to l
Lorem ipsum: https://github.com/plataformatec/devise
结果会是这样的
Lorem ipsum: https://github.com/plataforma...
要输出被截断的文本,可以使用内置的字符串功能
<%= link[0..19] %>
如果您希望将其作为链接的一部分,但希望导航上的完整链接,可能类似于:
<%= link_to link[0..19], url_for(link) %>
要输出被截断的文本,可以使用内置的字符串功能
<%= link[0..19] %>
如果您希望将其作为链接的一部分,但希望导航上的完整链接,可能类似于:
<%= link_to link[0..19], url_for(link) %>
要输出被截断的文本,可以使用内置的字符串功能
<%= link[0..19] %>
如果您希望将其作为链接的一部分,但希望导航上的完整链接,可能类似于:
<%= link_to link[0..19], url_for(link) %>
要输出被截断的文本,可以使用内置的字符串功能
<%= link[0..19] %>
如果您希望将其作为链接的一部分,但希望导航上的完整链接,可能类似于:
<%= link_to link[0..19], url_for(link) %>
要从哪一端截断 使用
String#[]
可以从任意一端获取子字符串:
s = "string with more than twenty characters"
s[0, 20] # get the first 20 characters
=> "string with more tha"
s[s.size-20, s.size] # the last 20 characters
=> "an twenty characters"
Rails还将该方法添加到字符串:
"string with more than twenty characters".truncate(20)
=> "string with more ..."
"string with more than twenty characters".truncate(20, omission: "")
=> "string with more tha"
希望有帮助。您希望从哪一端截断 使用
String#[]
可以从任意一端获取子字符串:
s = "string with more than twenty characters"
s[0, 20] # get the first 20 characters
=> "string with more tha"
s[s.size-20, s.size] # the last 20 characters
=> "an twenty characters"
Rails还将该方法添加到字符串:
"string with more than twenty characters".truncate(20)
=> "string with more ..."
"string with more than twenty characters".truncate(20, omission: "")
=> "string with more tha"
希望有帮助。您希望从哪一端截断 使用
String#[]
可以从任意一端获取子字符串:
s = "string with more than twenty characters"
s[0, 20] # get the first 20 characters
=> "string with more tha"
s[s.size-20, s.size] # the last 20 characters
=> "an twenty characters"
Rails还将该方法添加到字符串:
"string with more than twenty characters".truncate(20)
=> "string with more ..."
"string with more than twenty characters".truncate(20, omission: "")
=> "string with more tha"
希望有帮助。您希望从哪一端截断 使用
String#[]
可以从任意一端获取子字符串:
s = "string with more than twenty characters"
s[0, 20] # get the first 20 characters
=> "string with more tha"
s[s.size-20, s.size] # the last 20 characters
=> "an twenty characters"
Rails还将该方法添加到字符串:
"string with more than twenty characters".truncate(20)
=> "string with more ..."
"string with more than twenty characters".truncate(20, omission: "")
=> "string with more tha"
希望对您有所帮助。您能显示您的示例输入和示例输出吗。@vee用户输入正常的注释,如果它输入了需要切断的链接。例如:
Lorem ipsum:https://github.com/plataformatec/devise
结果应该是这样的<代码>Lorem ipsum:https://github.com/plataforma...您能显示您的示例输入和示例输出吗。@vee用户输入正常注释,如果它输入了需要切断的链接。例如:Lorem ipsum:https://github.com/plataformatec/devise
结果应该是这样的<代码>Lorem ipsum:https://github.com/plataforma...您能显示您的示例输入和示例输出吗。@vee用户输入正常注释,如果它输入了需要切断的链接。例如:Lorem ipsum:https://github.com/plataformatec/devise
结果应该是这样的<代码>Lorem ipsum:https://github.com/plataforma...您能显示您的示例输入和示例输出吗。@vee用户输入正常注释,如果它输入了需要切断的链接。例如:Lorem ipsum:https://github.com/plataformatec/devise
结果应该是这样的<代码>Lorem ipsum:https://github.com/plataforma...如果评论中有链接,我需要切断它。为此,我认为有必要回调?如果评论中有链接,我需要切断链接。为此,我认为有必要回调?如果评论中有链接,我需要切断链接。为此,我认为有必要回调?如果评论中有链接,我需要切断链接。为此,我认为有必要回调吗?